//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  TopView.m
//  Pizza
//
//  Created by sendInfo on 2015-03-24.
//  Copyright (c) 2015年 sendInfo. All rights reserved.
//

#import "TopView.h"

#pragma mark -

@interface TopView(){


    BeeUITextField *_tff;
}

@end


@implementation TopView

DEF_SIGNAL(HEADBTNCLICK)
DEF_SIGNAL(GOTOCART)
DEF_SIGNAL(beginsearch)
SUPPORT_AUTOMATIC_LAYOUT( YES )
SUPPORT_RESOURCE_LOADING( YES )

- (void)load
{
    
    //首页顶部背景
    UIView *headBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.size.height)];
    headBg.backgroundColor = [UIColor clearColor];
    [self addSubview:headBg];
    UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"120"]];
    logo.frame = CGRectMake(20, 10, 80, 90);
    [headBg addSubview:logo];
    
    for (int i =0; i<4; i++) {
        
        NSString *imgName = [NSString stringWithFormat:@"top-%d",i];
        BeeUIButton *btn = [[BeeUIButton alloc] initWithFrame:CGRectMake(5+CGRectGetMaxX(logo.frame)+(i*50+5), 35, 50, 50)];
        btn.tag = i+100;
        [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setBackgroundImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
        [headBg addSubview:btn];
    }
    
    BeeUITextField *tf = [[BeeUITextField alloc] initWithFrame:CGRectMake(10+CGRectGetMaxX(logo.frame), 40+45, 200, 35)];
    tf.tag = 9999;
    _tff = tf;
    tf.placeholder = @"请输入店铺名";
    tf.layer.cornerRadius = 8;
    tf.layer.masksToBounds = YES;
    tf.font = [UIFont systemFontOfSize:14];
    tf.textColor = [UIColor blackColor];
    tf.backgroundImage = [UIImage imageNamed:@"search-bg"];
    tf.borderStyle = UITextBorderStyleNone;
    [headBg addSubview:tf];
    UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchicon"]];
    imgv.frame = CGRectMake(200-31, 3, 30, 30);
    [tf addSubview:imgv];
    
    BeeUIButton *btnmask = [[BeeUIButton alloc] initWithFrame:CGRectMake(200-40, 0, 40, 40)];

    [btnmask addTarget:self action:@selector(startsearch) forControlEvents:UIControlEventTouchUpInside];
    [tf addSubview:btnmask];
    
    
    
    UIImageView *midimgvbg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"middBg"]];
    midimgvbg.frame = CGRectMake(0, CGRectGetMaxY(tf.frame), 1446/2, 35);
    [headBg addSubview:midimgvbg];
    
    UIButton *cartBtn = [[UIButton alloc] initWithFrame:CGRectMake(230, CGRectGetMaxY(tf.frame), 35, 35)];
    [headBg addSubview:cartBtn];
    [cartBtn addTarget:self action:@selector(gotoCart) forControlEvents:UIControlEventTouchUpInside];
    [cartBtn setBackgroundImage:[UIImage imageFromString:@"cart_home_icon"] forState:UIControlStateNormal];
    [cartBtn bringSubviewToFront:cartBtn];
    
}
- (void)gotoCart{

    [self sendUISignal:self.GOTOCART];
}

- (void)unload
{
}

- (void)dataDidChanged
{
    // TODO: fill data
}

- (void)layoutDidFinish
{
    // TODO: custom layout here
    self.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
}
-(void)btnclick:(BeeUIButton*)btn
{
    
    [self sendUISignal:self.HEADBTNCLICK withObject:btn];


}
- (void)startsearch
{

    [self sendUISignal:self.beginsearch withObject:_tff.text];

}
@end
